package com.example.onlinemusicserver2024.controller;


import com.example.onlinemusicserver2024.common.R;
import com.example.onlinemusicserver2024.service.RecommendService;
import com.example.onlinemusicserver2024.service.SongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SongController {

    @Autowired
    SongService songService;

    @Autowired
    RecommendService recommendService;

    /**
     * 根据歌曲ID查询歌曲的信息
     */
    // http://localhost:8888/song/detail?id=7
    @GetMapping("/song/detail")
    public R getSong(@RequestParam int id) {
        System.out.println("根据ID查询歌曲，id=" + id);
        R result = songService.getSongDetail(id);
        return result;
    }

    /**
     * 根据歌手id获取歌曲列表
     *
     * @param singerId
     * @return
     */
    @GetMapping("/song/singer/detail")
    public R selectSongListBySingerId(@RequestParam int singerId) {
        System.out.println("获取歌曲列表，singId=" + singerId);
        R result = songService.selectSongListBySingerId(singerId);
        return result;
    }

    @GetMapping("/song")
    public R allSong() {
        System.out.println("查询所有歌曲");
        R result = songService.allSongs();
        return result;
    }

    /**
     * 根据歌名模糊查询歌曲
     *
     * @param name
     * @return
     */
    @GetMapping("/song/singerName/detail")
    public R querySongsByName(@RequestParam String name) {
        System.out.println("查询歌曲：" + name);
        R result = songService.querySongsByName(name);
        return result;
    }

    @GetMapping("/song/recommend/{userId}")
    public R songRecommendByUserId(@PathVariable int userId) {
        return recommendService.songRecommendByUserId(userId);

    }

    /**
     * 判断歌曲是否已支付
     * @param songId
     * @param userId
     * @return
     */
    @GetMapping("/song/isPay")
    public R isPay(@RequestParam("songId") Integer songId,
                   @RequestParam("userId") Integer userId)  {
        return songService.isPay(songId,userId);
    }

}
